//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.mega.ycy.common;

import com.mega.ycy.GuiGameOver;
import com.mega.ycy.SBPlayer;
import com.mega.ycy.Yiciyuan_EVENT;
import com.mega.ycy.common.entity.DeleteRenderer;
import com.mega.ycy.common.entity.EntityDelete;
import com.mega.ycy.common.item.ItemLoader;
import com.mega.ycy.common.specialattack.Delete;
import mods.flammpfeil.slashblade.ItemSlashBladeNamed;
import mods.flammpfeil.slashblade.RecipeAwakeBlade;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.named.event.LoadEvent.InitEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketKeepAlive;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.server.FMLServerHandler;
import org.lwjgl.input.Mouse;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@SuppressWarnings("deprecation")
public class CommonProxy {
    public static MinecraftServer serverInstance; 
    public static int index = 0;

    public CommonProxy() {
    }

    public static void save(EntityPlayer player) {
        player.setSpawnPoint(player.getPosition(), true);
        player.getCooldownTracker().removeCooldown(ItemLoader.yiSlashBlade);
        player.hurtTime = 0;
        player.deathTime = 0;
        player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
        player.respawnPlayer();
        if (player instanceof EntityPlayerSP) {
            EntityPlayerSP sp = (EntityPlayerSP)player;
            sp.connection.handleKeepAlive(new SPacketKeepAlive());
            sp.capabilities.allowFlying = true;
            sp.capabilities.allowEdit = true;
            sp.capabilities.isCreativeMode = true;
            sp.sendPlayerAbilities();
            sp.addedToChunk = true;
            sp.onAddedToWorld();
        }

        if (player instanceof EntityPlayerMP) {
            EntityPlayerMP mp = (EntityPlayerMP)player;
            mp.onAddedToWorld();
        }

    }

    public static boolean isYcy(Entity entity) {
        return entity instanceof EntityPlayer && ((EntityPlayer)entity).inventory.hasItemStack(new ItemStack(ItemLoader.yiSlashBlade));
    }

    public void preInit(FMLPreInitializationEvent event) { 
        ItemSlashBlade.specialAttacks.put(678, new Delete());
        MinecraftForge.EVENT_BUS.register(new ItemLoader());
        MinecraftForge.EVENT_BUS.register(this);
        SlashBlade.InitEventBus.register(this);
        ScheduledExecutorService service1 = Executors.newSingleThreadScheduledExecutor();
        service1.scheduleAtFixedRate(Yiciyuan_EVENT::protectClientScreen, 5L, 5L, TimeUnit.NANOSECONDS);

    }

    public void init(FMLInitializationEvent event) {
        EntityRegistry.registerModEntity(new ResourceLocation("yicyuan", "Delete"), EntityDelete.class, "Delete", 30, Yiciyuan_EVENT.instance, 250, 200, true);
    }

    public void postInit(FMLPostInitializationEvent event) {
    }

    @SubscribeEvent
    public void register(Register<EntityEntry> event) {
        event.getRegistry().register(EntityEntryBuilder.create().entity(EntityDelete.class).id(new ResourceLocation("ycy", "ball"), 1).name("").build());
    }

    @SubscribeEvent
    public void bindEntityRenderer(ModelRegistryEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(EntityDelete.class, DeleteRenderer::new);
    }

    @SubscribeEvent(
            priority = EventPriority.LOWEST
    )
    public void init(InitEvent event) {
        String name = "flammpfeil.slashblade.named.yiciyuan";
        ItemStack yiblade = new ItemStack(ItemLoader.yiSlashBlade, 1, 0);
        NBTTagCompound tag = new NBTTagCompound();
        ItemSlashBladeNamed.CurrentItemName.set(tag, name);
        ItemSlashBladeNamed.CustomMaxDamage.set(tag, 100);
        ItemSlashBladeNamed.IsDefaultBewitched.set(tag, true);
        ItemSlashBlade.setBaseAttackModifier(tag, 100.0F);
        ItemSlashBlade.SpecialAttackType.set(tag, 678);
        ItemSlashBlade.TextureName.set(tag, "named/yiciyuan/texture");
        ItemSlashBlade.ModelName.set(tag, "named/yiciyuan/model");
        ItemSlashBlade.RepairCount.set(tag, 100000);
        ItemSlashBlade.KillCount.set(tag, 1000000);
        ItemSlashBlade.ProudSoul.set(tag, 1000000);
        tag.setBoolean("Unbreakable", true);
        yiblade.addEnchantment(Enchantments.INFINITY, 100);
        yiblade.setTagCompound(tag);
        NBTTagList loreList = new NBTTagList();
        loreList.appendTag(new NBTTagString(I18n.translateToLocal("info.yiciyuan.1")));
        loreList.appendTag(new NBTTagString(""));
        loreList.appendTag(new NBTTagString(I18n.translateToLocal("info.yiciyuan.2")));
        loreList.appendTag(new NBTTagString(""));
        loreList.appendTag(new NBTTagString(I18n.translateToLocal("info.yiciyuan.3")));
        loreList.appendTag(new NBTTagString(""));
        loreList.appendTag(new NBTTagString(I18n.translateToLocal("info.yiciyuan.4")));
        loreList.appendTag(new NBTTagString(""));
        loreList.appendTag(new NBTTagString(I18n.translateToLocal("info.yiciyuan.5")));
        SlashBlade.registerCustomItemStack(name, yiblade);  ItemStack egg1 = new ItemStack(Blocks.DRAGON_EGG);
        ItemStack netherstar = new ItemStack(Items.NETHER_STAR);
        ItemStack yamato = SlashBlade.getCustomBlade("flammpfeil.slashblade", "flammpfeil.slashblade.named.yamato");
        ItemStack blade = SlashBlade.getCustomBlade("flammpfeil.slashblade", "slashblade");
        SlashBlade.addRecipe(name, new RecipeAwakeBlade(new ResourceLocation("flammpfeil.slashblade", "yiciyuan"), SlashBlade.getCustomBlade("flammpfeil.slashblade", name), ItemStack.EMPTY, "XTX", "VBV", "XVX", 'X', blade, 'T', egg1, 'V', netherstar, 'B', yamato));
    }

    public static void createFinalDeathScreen(Minecraft mc) {
        try {
            if (mc.world != null) {
                if (!(mc.currentScreen instanceof GuiGameOver)) {
                    mc.currentScreen = new GuiGameOver(null);
                }
            }
        } catch (Throwable var7) {
            var7.printStackTrace();
        }
    }

    public static void INIT_FINAL_DEATHSCREEN(Minecraft mc) {
        try {
            if (mc.world != null) {
                GuiGameOver gui = new GuiGameOver(null);
                    ScaledResolution scaledresolution = new ScaledResolution(mc);
                    int i1 = scaledresolution.getScaledWidth();
                    int j1 = scaledresolution.getScaledHeight();
                    int k1 = Mouse.getX() * i1 / mc.displayWidth;
                    int l1 = j1 - Mouse.getY() * j1 / mc.displayHeight - 1;
                    gui.setWorldAndResolution(mc, scaledresolution.getScaledWidth(), scaledresolution.getScaledHeight());
                    gui.drawScreen(k1, l1, mc.getTickLength());
            }
        } catch (Throwable var7) {
            var7.printStackTrace();
        }
    }
}
